
let searchParams = new URLSearchParams(location.search.slice(1));

let pid = searchParams.get('pid');
let uid = localStorage.getItem('id');

let itemAPI = 'http://jx.xuzhixiang.top/ap/api/detail.php';

$.get(itemAPI, {
    id: pid
}).then(res => {
    let pobj = res.data;
    let html = `<div class="innerleft">
    <p>${pobj.pname}${pobj.pdesc}</p>
    <h2>
        <img src="${pobj.pimg}" alt="">
    </h2>
    <p>
        <span>滋润</span>
        <span>遮瑕</span>
        <span>防晒</span>
        <span>修容</span>
        <i>分享到&gt;</i>
    </p>
</div>
<div class="innerright">
    <img src="../img/country.png" alt="">
    <span></span>
    <h2>${pobj.pprice}</h2>
    <span></span>
    <p><i>107人</i>已购买</p>
    <span></span>
    <p>包邮政策：本商品单件包邮 （新疆部分地区除外）<br>
        服务政策：本商品不支持退货<br>
        国家药监局提示您：<br>
        <b>请正确认识化妆品功效，化妆品不能替代药<br>
            品，不能治疗皮肤病等疾病</b><br>
        型&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：<select name="" id="" class="selects">
            <option value="">请选择型号</option>
        </select></p>
    <span></span>
    <button class="add-btn">加入购物车&gt;</button>
</div>`

    $(`<div>${html}</div>`).appendTo('.inner')

    let pnum = 1
    $('.add-btn').click(function () {
        let addAPI = 'http://jx.xuzhixiang.top/ap/api/add-product.php'

        $.get(addAPI, {
            pid,
            uid,
            pnum,
        }).then(res => {
            alert('加入购物车成功')
        })
    })
})